/**
 * @copyright 2025 银杏ERP
 * @author 银杏ERP
 * @version 1.0
 * @license http://www.hhyx.xyz
 * @developer Lhf
 */

namespace app\admin\event;

use app\admin\service\yxerp\InventoryService;

class WarehouseOperationEvent
{
    /**
     * 监听仓库操作审核事件
     */
    public function onWarehouseOperationApproved($operation)
    {
        if ($operation['direction'] == 1) {
            // 处理入库
            InventoryService::processInbound($operation);
        } else {
            // 处理出库
            InventoryService::processOutbound($operation);
        }
    }
    
    /**
     * 监听仓库操作反审核事件
     */
    public function onWarehouseOperationUnapproved($operation)
    {
        if ($operation['direction'] == 1) {
            // 处理反入库
            InventoryService::processReverseInbound($operation);
        } else {
            // 处理反出库
            InventoryService::processReverseOutbound($operation);
        }
    }
    
    /**
     * 注册事件
     */
    public static function register()
    {
        // 监听仓库操作审核事件
        \think\facade\Event::listen('warehouse_operation_approved', function ($operation) {
            (new self())->onWarehouseOperationApproved($operation);
        });
        
        // 监听仓库操作反审核事件
        \think\facade\Event::listen('warehouse_operation_unapproved', function ($operation) {
            (new self())->onWarehouseOperationUnapproved($operation);
        });
    }
} 